import requests
import parsel
headers={
 'user-agent': 'Mozilla/5.e (Windons NI 18.8; Winb4;x54)AppleWebkit/537.36(KHIML,like Gecko) Chrome/113.0.0.8 Safari/537.36', 'x-requested-with': 'XMLiIttpHequest',

}
#循环
#for page in range(1,3):
    #print(f'=========正在爬取第{page}页============')
url = 'https://bizhi.cheetahfun.com/dn/c3j/'
response = requests.get(url=url, headers=headers)
response.encoding = response.apparent_encoding
#print(response.text) 
selector = parsel.Selector(response.text)
href_list = selector.xpath('//div[@class="overflow-hidden relative rounded-sm w-79 mx-1 mb-3 h-40"]/a/@href').getall()
#print(img_name)
for href in href_list:
        href_date = requests.get(url=href,headers=headers).text
        selector_2 = parsel.Selector(href_date)
        img_url = selector_2.xpath('//div[@class="relative mb-3 float-left" ]/img/@src').get()#
        img_name = selector_2.xpath('//div[@class="relative mb-3 float-left" ]/img/@title').get()
        img_date = requests.get(url=img_url,headers=headers).content
        with open('img2\\'+ img_name + '.jpg',mode = 'wb') as f:
            f.write(img_date)
            print('保存完成：', img_name)
        
        
